package helloworld;

import org.omg.CORBA.*;
import org.omg.PortableServer.*;

import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import helloApp.HelloItfPOA;

class HelloImpl extends HelloItfPOA {


  public String concat(String a, String b) {
    return a+b;
  }
  
  public String sayDate(){

	SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd" ); 
	Date currentTime_1 = new Date(); 
	return formatter.format(currentTime_1);
  }
}

public class HelloServer {

  public static void main(String args[]) {
    try{
      // create and initialize the ORB
      ORB orb = ORB.init(args, null);

      // get reference to rootpoa & activate the POAManager
      POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
      rootpoa.the_POAManager().activate();

      // create servant and register it with the ORB
      HelloImpl helloImpl = new HelloImpl();

      org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImpl);      
      
      String IORenString = orb.object_to_string(ref);
      FileWriter fw = new FileWriter("FicPourIOR");
      fw.write(IORenString);
      fw.close();

      System.out.println("server ready...");

      // wait for invocations from clients
      orb.run();
    }

      catch (Exception e) {
        System.err.println("ERROR: " + e);
        e.printStackTrace(System.out);
      }


  }
}

